import { useResponseSuccess } from '~/utils/response';

export default eventHandler(async (event) => {
  const query = getQuery(event);
  const { startDate, endDate, groupBy = 'day', contextId } = query;

  // 生成模拟的趋势数据
  const generateTrendData = () => {
    const data = [];
    const start = new Date(startDate as string);
    const end = new Date(endDate as string);

    for (let d = new Date(start); d <= end; d.setDate(d.getDate() + 1)) {
      const dateStr = d.toISOString().split('T')[0];
      data.push({
        date: dateStr,
        bookings: Math.floor(Math.random() * 50) + 10,
        completed: Math.floor(Math.random() * 40) + 5,
        cancelled: Math.floor(Math.random() * 5) + 1,
      });
    }

    return data;
  };

  const trends = generateTrendData();

  return useResponseSuccess(trends);
});
